<?php
$servername = "39.107.234.166:3306";
$username = "root";
$password = "123456";
$dbname = "ip";
$conn = mysqli_connect($servername, $username, $password, $dbname);
$conn->query("SET NAMES 'UTF8'");

$ip_s=isset( $_POST['ip'] ) ? $_POST['ip'] : '没有获取到ip地址';
$addre=isset($_POST["adress"]) ? $_POST['adress'] : '没有获取到城市地址';
$create_time=isset($_POST["create_at"]) ? $_POST["create_at"]:'没有获取到创建时间';
$last_time=isset($_POST["last_at"]) ? $_POST["last_at"]:'没有获取到最后访问时间';
$sorts=isset($_POST["sorting"]) ? $_POST["sorting"]:'没有获取到排序时间';

$select = "SELECT ip FROM ip_adress WHERE ip='$ip_s'";
$result = mysqli_query($conn, $select);
 
if (mysqli_num_rows($result) > 0) {
    $update="UPDATE ip_adress SET last_at='$last_time', sorting='$sorts'  WHERE ip='$ip_s'";
    if (mysqli_query($conn, $update)) {echo "ip update ok";}
    mysqli_close($conn);
} else {
    $sql = "INSERT INTO ip_adress (ip, addres, create_at, last_at, sorting) VALUES ('$ip_s','$addre','$create_time','$last_time','$sorts')";
    if (mysqli_query($conn, $sql)) {echo "ip create ok";}
    mysqli_close($conn);
}


?>